package com.spring.rabbitmq.routing.direct;

import com.rabbitmq.client.*;
import com.spring.rabbitmq.utils.RabbitMQUtils;
import lombok.SneakyThrows;

import java.io.IOException;

/**
 * @Author: lzx
 * @Data: 2021/04/29/9:59
 * @Description：
 */
public class Customer2 {
    @SneakyThrows
    public static void main(String[] args) {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();
        //声明交换机
        channel.exchangeDeclare("logs_direct", "direct");
        String queue = channel.queueDeclare().getQueue();
        //临时队列绑定
        channel.queueBind(queue, "logs_direct", "error");
        //发布消息
        channel.basicConsume(queue, true, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者2:" + new String(body));
            }
        });



    }
}
